from flask import Flask, make_response
from flask_cors import CORS
from flask_sqlalchemy import SQLAlchemy
import flask_login
# from models import User

"""
主要用于生成flask app, 以及login_manager关联
"""

def creat_app():
    # app = Flask(__name__, static_folder='./')
    app = Flask(__name__, static_folder='./data', static_url_path='/data')
    # app.config.from_object(__name__)
    app.secret_key = 'zhang'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:password@db/syl_sys?charset=utf8'
    # app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:root@127.0.0.1/syl_sys?charset=utf8'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    return app

app = creat_app()
CORS(app, resources={r"/*": {"origins": "*"}}, supports_credentials=True)

db = SQLAlchemy(app)

login_manager = flask_login.LoginManager() # 使用log_manager去管理session
login_manager.session_protection = 'strong'
# login_manager.login_view = 'login'
login_manager.init_app(app)